PostOffice
// :doObj('add,'PostOffice)
// :doObj('build,'PostOffice)
// :doObj('remove,'PostOffice)
{
// 
// (c)1994, 1995 by Serg Koren.  All rights reserved.
// Do not distribute modified or NTK versions.
// Shareware $8 to
// 485 Brown Briar Cir.
// Horsham,PA 19044-1974
// 

	viewclass: 'clView,
	viewFlags: vFloating + vApplication,
	viewFormat: 337,
	declareSelf: 'base,
	title: "Post Office",
	ViewBounds: RelBounds(10,5,220,100),
	curEntry : {},
	soupName : "Post:SKoren",
	defaultEntry:  {   pho: "", loc: ""},
	mySoup : nil,
	soupCursor : nil,
	editView : nil,

	_package: {
		version: 200,
		copyright: ")1994, 1995 by S.Koren.\u000D\u All rights reserved",
		devSignature: "SKoren",
		icon: :GetIcon("Post Office"),
	},

	RegisterCardSoup: kRegisterCardSoupFunc,
	UnregisterCardSoup: kUnregisterCardSoupFunc,
	GetUserConfig: kGetUserConfigFunc,
	SetUserConfig: kSetUserConfigFunc,
	FlushUserConfig: kFlushUserConfigFunc,

	setEntry: func(entry)
		curEntry := if entry then
			entry
		else
			deepclone(defaultEntry),

	viewSetupFormScript:
	func()
	begin
		editView := self;

		mySoup := :RegisterCardSoup(soupName, [], appSymbol, []);
		soupCursor := Query(mySoup,{type: 'index}); 
		:setEntry(soupCursor:entry()); 

		if StrEqual(curEntry.loc,"") then
		begin
			curEntry.pho := :GetUserConfig('mailPhone); 
			curEntry.loc := :GetUserConfig('location.name); 
			mySoup:AddToDefaultStore(curEntry);
		end; 
	
		GetRoot().ExtrasDrawer:close();
		RefreshViews();
	
		inherited:?viewSetupFormScript();
		
	end,

	viewQuitScript: func()
	begin

		// close help...
		if helpView then
			helpView:close();
		helpView := nil;

		// get rid of soup...
		mySoup := soupCursor := nil;
		:UnRegisterCardSoup(soupName);
		inherited:?viewQuitScript();
	end,

	
}
-----
PostOffice.add+changeBtn
{
// set Change button

		_proto: 'protoTextButton,
		viewBounds: RelBounds(115, 70, 45, 16),
		text: "Change",

		buttonClickScript: func()
		begin
		
			curEntry.loc := loc.text;
			curEntry.pho := phone.text;
			locPicker.labelCommands[state] := loc.text;
			Picker.labelCommands[state] := phone.text;
			modPicker.labelCommands[state] := loc.text & "@" & phone.text;
			:Flush();
		
		end;

}

-----
PostOffice.about+maboutText
{
// about text

	viewclass: 'clParagraphView,
	
	text: " \u000D\u " && PostOffice._package.copyright && "\u000D\u Version" && SubStr( NumberStr(PostOffice._package.version),0,1) & "." & SubStr( NumberStr(PostOffice._package.version),1,2) & "\u000D\u email:  SergK@eworld.com",
	viewFlags: 3,
	viewBounds: RelBounds(5,20,200,80),
}
-----
PostOffice+SetsBtn
{
// button for soup set maintenance

	_proto: 'protoTextButton,
	text : "Sets...",
	
	viewBounds: RelBounds(5,5,40,16),

	buttonClickScript:func()
	begin
			:setEntry(nil);
			add:open();
	end;
	
}

-----
PostOffice+about
{
// float n go for about

		_proto:'protoFloatNGo,
       viewBounds:RelBounds(0,5,200,90),
}


-----
PostOffice+Status
{
// current setting line

		_proto: 'protoStaticText,
		viewBounds: RelBounds(65,87,200,16),
		text:  nil, 

		viewSetupFormScript: func()
		text := :GetUserConfig('location.name) & "@" & :GetUserConfig('mailPhone),  // force update

}

-----
PostOffice+picker
{
// phone picker

	_proto: 'protoLabelPicker,
	text: "Phones",
	viewBounds: RelBounds(50,50,150,16),
	labelCommands: nil,
		

	viewSetupFormScript: func()
	begin 
		labelCommands:= [];
		local e, curs, soup;
		soup := GetUnionSoup("Post:SKoren");
		// get every phone entry...
		labelCommands := MapCursor(Query(soup,{type: 'index}),func (e) e.pho);
		inherited:viewSetupFormScript();
	end,

	labelActionScript: func(cmd)
	begin
		SetValue(Status, 'text, locpicker.labelCommands[cmd] & "@" &  labelCommands[cmd] );
		:SetUserConfig('location.name, locpicker.labelCommands[cmd]);
		:SetUserConfig('mailPhone, labelCommands[cmd]);
		:FlushUserConfig();
		// switch to the one chosen...
		locpicker:UpdateText(locpicker.labelCommands[cmd]);
	end;
}

-----
PostOffice+locpicker
{
// location picker

	_proto: 'protoLabelPicker,
	text: "Locations",
	viewBounds: RelBounds(50,30,150,16),	
	labelCommands: nil,

	viewSetupFormScript: func()
	begin 
		labelCommands:= [];
		local e, curs, soup;
		soup := GetUnionSoup("Post:SKoren");
		// get all the locations...
		labelCommands := MapCursor(Query(soup, {type: 'index}),func (e) e.loc);	
		inherited:viewSetupFormScript();
	 end,

	labelActionScript: func(cmd)
	begin

		SetValue(Status, 'text, labelCommands[cmd] & "@" & picker.labelCommands[cmd]);
		:SetUserConfig('location.name, labelCommands[cmd]);			
		:SetUserConfig('mailPhone, picker.labelCommands[cmd]);
		:FlushUserConfig();
		// switch to current...
		picker:UpdateText(picker.labelCommands[cmd]);
	end;
}

-----
PostOffice+add
{
// float n go for sets

	_proto:'protoFloatNGo,
    viewBounds:RelBounds(0,5,200,90),
	viewFlags:  512,
	state : 0,	// index of modpicker
}


-----
PostOffice.about+title
{
// about title

	_proto: 'protoStaticText,
	viewBounds: RelBounds(20,10,100,16),
	text: "Post Office",
}


-----
PostOffice.add+label1
{
// label

	_proto: 'protoStaticText,
	viewBounds: RelBounds(5,30,100,16),
	text: "Location:",
}


-----
PostOffice.add+label2
{
// label
	
	_proto: 'protoStaticText,
	viewBounds: RelBounds(5,50,100,16),
	text: "Phone:",
}


-----
PostOffice.InputLineproto
{
// my proto for input

	_proto: 'protoInputLine,
	text: "",
	value: 0,


	viewSetupFormScript: func()
	begin	
		self.text := clone(curEntry.(field)); // clone the field's "field" slot.
		inherited:?viewSetupFormScript();
	end;
}

-----
PostOffice.add+Loc
{
// location input line

	_proto: 'InputLineproto,		
	viewBounds: RelBounds(60,20,130,30),
	viewFlags: 6657,
	field: 'loc,	// create a slot which points to loc

}

-----
PostOffice.add+Phone
{
// phone input line

	_proto: 'InputLineproto,		
	viewBounds: RelBounds(60,40,130,30),
	viewFlags: 10753,
	field: 'pho, // create a slot which points to pho

}

-----
PostOffice.Flush
func()
begin
// flushes soup entries

	if isSoupEntry(curEntry) then
		EntryChange(curEntry)
	else
		mySoup:AddToDefaultStore(curEntry);
end

-----
PostOffice.add+modpicker
{
// set picker

	_proto: 'protoLabelPicker,
	text: "-",
	viewBounds: RelBounds(30,5,200,16),
	labelCommands: nil,

	viewSetupFormScript: func()
	begin 
		labelCommands:= [];
		local e, curs, soup;
		soup := GetUnionSoup("Post:SKoren");
		// get all locations and phones...
		labelCommands := MapCursor(Query(soup,{type: 'index}), func(e) e.loc & "@" & e.pho);
		inherited:viewSetupFormScript();
	end,

	
	labelActionScript: func(cmd)
	begin
		local e, curs, soup;
		soup := GetUnionSoup("Post:SKoren");
		curs := Query(soup, {type: 'index});
		state := cmd;
			
		curs:Move(cmd);	// move to selected entry in soup
		e:= curs:Entry();	
		SetValue(phone, 'text,clone(e.pho));
		SetValue(loc,'text, clone(e.loc));	
	end;
}

-----
PostOffice.add+addBtn
{
// multistate New button...
// ...function dependant on btn text
// ...btn text set by other buttons.

	_proto: 'protoTextButton,
	viewBounds: RelBounds(5, 70, 45, 16),
	text: "New",

	buttonClickScript: func()
	begin 
		local e, curs, soup;
		if StrEqual(text, "New") then
		begin
			// default...clear the inputs 
			// ...and get ready to add.
			phone.text := "";
			loc.text := "";
			text := "Add";
			SetValue(self,'text,"Add");
			SetValue(delBtn,'text,"Cancel");
			changeBtn:Hide();
		end
		else if StrEqual(text, "Confirm") then
		begin
			// delete the entry the modpicker points to...
			soup := GetUnionSoup("Post:SKoren");
			curs := Query(soup, {type: 'index});
				
			curs:Move(state);	// move to entry in modpicker
			e:= curs:Entry();	
			if isSoupEntry(e) then
				EntryRemoveFromSoup(e);
			SetValue(self,'text,"New");
			SetValue(delBtn,'text,"Delete");
			changeBtn:Show();	
			// remove the corresponding entries in the pickers...			
			ArrayRemoveCount(modpicker.labelCommands, state,1);
			ArrayRemoveCount(locpicker.labelCommands, state,1);
			ArrayRemoveCount(picker.labelCommands, state,1); 
			modpicker:UpdateText(modpicker.labelCommands[0]);
		end
		else
		begin 
			// add...we've entered stuff into input lines...
			:setEntry(nil);
			curEntry.loc := loc.text;
			curEntry.pho := phone.text;
			:Flush();
			// add the info to all the pickers...
			AddArraySlot(locpicker.labelCommands, loc.text);		AddArraySlot(picker.labelCommands, phone.text);
			AddArraySlot(modpicker.labelCommands, loc.text & "@" & phone.text);
			SetValue(self,'text,"New");
			SetValue(delBtn,'text,"Delete");
			changeBtn:Show();
		end;
	end;

}

-----
PostOffice.add+delBtn
{
// set Delete button

	_proto: 'protoTextButton,
	viewBounds: RelBounds(60, 70, 45, 16),
	text: "Delete",

	buttonClickScript: func()
	begin
		if StrEqual(text, "Delete") then
		begin
			SetValue(self,'text,"Cancel");					SetValue(addBtn,'text,"Confirm");
			changeBtn:Hide();
		end
		else
		begin
			SetValue(self,'text,"Delete");
			SetValue(addBtn,'text,"New");
			changeBtn:Show();
		end;
	end;

}

-----
PostOffice+stat
{
// protostatus line

	_proto: 'protoStatus, 

	// func used to position buttons
	ButtonBounds: func(width)
	begin
		local left1 := 25, top := 2, spacing := 6, bottom := 15;

		if width > 0 then
			SetBounds(spacing,top,spacing+width,bottom)
		else
			SetBounds(left1,top,left1 - width,bottom);
	end,

}

-----
PostOffice.stat+helpBtn
{
// help button on protostatus

	_proto: 'protoTextButton,
	viewBounds: :ButtonBounds(10),
	text: "?",
	viewJustify: 8389638,

	buttonClickScript: func()
	:openHelp(),

}

-----
PostOffice.stat+aboutBtn
{
// about button on protostatus

	_proto: 'protoTextButton,
	viewBounds: :ButtonBounds(-10),	
	text: "!",

	buttonClickScript: func()
	about:open(),
}

-----
PostOffice.helpStuff~
{
// help setup

	helpBook: :helpBookTemplate(),
	helpView: nil,
	
	openHelp: func()
		if helpBook then
		begin
			if not helpView then
				helpView := BuildContext(
					{ _proto: GetRoot().TinyTim._proto,
					bookRef: helpBook
					});
			GetRoot().TinyTim:close();
			helpView:openManual(helpBook);
		end,

	
}


-----
PostOffice.helpBook+Page1
.# first help book page
.subject 1
About Post Office
.story
Post Office lets you maintain multiple NewtonMail phone numbers and corresponding locations.  


It lets you easily switch between sets of these as you travel or commute.

-----
PostOffice.helpBook+Page2
.subject 1
Main View
.story
The Post Office main view, is the one you see when you start the app.  It contains two pickers, a status line, a "Sets..." button, and 2 buttons on the status line.

-----
PostOffice.helpBook+Page3
.subject 1
Main View Objects
.story
- The "Sets..." button takes y ou to the Sets View.
- The "!" brings up an about box with version information.
- The "?" brings up this help.
- The Status line displays the current NewtonMail information.
- The Location picker allows you to select a NewtonMail set by its location.
- The Phone picker allows you to select a NewtonMail set by its access number


-----
PostOffice.helpBook+Page4
.subject 1
What Are Sets?
.story
A "set" as defined by Post Office is a NewtonMail access phone number and the corresponding location.


Post Office lets you maintain sets.

-----
PostOffice.helpBook+Page5
.subject 1
Sets View
.story
The Post Office sets view is where you maintain access location and numbers for NewtonMail.  This view consists of one picker, two input lines, and three buttons.

-----
PostOffice.helpBook+Page6
.subject 1
Sets View Objects
.story
-The picker allows you to select which existing set you wish to change or delete.
-The two input lines allow you to add new sets or modify the information in an existing one.
-The three buttons are "New", "Delete" "Change", and perform the function as labelled.


-----
PostOffice.helpBook+Page7
.subject 1
How Do I Add A New Set?
.story
-Scrub out the information in the input lines.
-Enter the new information.
-Click the "New" button.
-Confirm by clicking the "Add" button.

-----
PostOffice.helpBook+Page8
.subject 1
How Do I Delete A Set?
.story
-Select the set to be deleted from the picker
-Click the "Delete" button.
-Confirm by clicking the "Confirm" button.

-----
PostOffice.helpBook+Page9
.subject 1
How Do I Change A Set?
.story
-Select the set to be changed from the picker
-Enter the modified information in the input lines.
-Click the "Change" button.

-----
PostOffice.helpBook+Page91
.subject 1
About Newt 3.0
.story
Post Office was written using Newt 3.0 by Steve Weyer.

"Newt 3.0
a native development environment for simple applications using NewtonScript, and for creating turtle-like graphics using gestures, buttons, and NS. "

Newt 3.0 runs on your Newton and produces standalone packages without a desktop computer.

Steve Weyer - weyer@netaxs.com
-----
PostOffice.helpBook+Page92
.subject 1
About The Author
.story
Serg Koren
485 Brown Briar Cir.
Horsham, PA 19044-1974

Post Office is shareware: $8

SergK@eworld.com
archimag@netaxs.com
WizLord@aol.com
http://www.netaxs.com/~archimag/Newton.html

-----
PostOffice.helpBook+Page93
.subject 1
Disclaimers & Limitations
.story
Post Office is provided as is. 
Post Office creates a soup called "Post:SKoren".
Post Office also modifies the userConfiguration soup.


-----
GetIcon
func(which)
begin
	
		local iconsoup := GetUnionSoup("Icons:BenG");
		local entry :=  (cursor := Query(iconsoup, {type: 'index})):entry();

		while entry do
		begin

			if StrEqual(entry.name, which) then 
				return entry.icon;

			entry := cursor:Next();
			
		end;

		return nil;
end
-----
PostOffice.helpBook+Page94
.subject 1
Registration
.story
Post Office is shareware.
Please send $8 if you find this useful to:

Serg Koren
485 Brown Briar Cir.
Horsham, PA 19044-1974


-----
_PostOffice._about+title
 {
// about box title

	_proto: 'protoStaticText,
	viewBounds: RelBounds(20,20,100,16),
	text: "   Post Office",
}



-----
